package Chapter8;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

/**
 * Created by m.zabarylo on 10/10/2014.
 */
public class NavTimmingDemo {
    private WebDriver driver;

    @Before
    public void setUp(){ driver = new FirefoxDriver();}

    @Test
    public void testBMINav() throws Exception
    {
        driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");

        JavascriptExecutor js = (JavascriptExecutor) driver;

        //get the Load Event End
        long loadEventEnd = (Long) js.executeScript("return window.performance.timing.loadEventEnd;");
        //get the navigation event start
        long navigationStart = (Long) js.executeScript("return window.performance.timing.navigationStart;");
        //difference between load event end and navigation start is Page Load Time
        System.out.println("Page Load Time Is " + (loadEventEnd - navigationStart)/1000 + " seconds");


    }
    @After
    public void tearDown()
    {
        driver.quit();
    }
}
